<?php
namespace UserApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class RegistrationApiController extends AbstractRestfulController
{
    public function getList()
    {			
			
    }
    public function get($user_id)
    {		
		header('Access-Control-Allow-Origin: *');
		$data=array();		
		$userTable=$this->getServiceLocator()->get('Models\Model\UserFactory');
		$userDataArr = $userTable->getUserData($user_id)->toarray();
		$userData="";
		if( isset($userDataArr[0]) )
		{
			$userDataArr[0]["dosageDetails"]=array();
			$userDataArr[0]["tabletNamee"]="";
			$userDataArr[0]["quantityy"]="";
			$userData=$userDataArr[0];
		}
		if(count($userData)!=0){
			return new JsonModel(array(
				'data' 		=> $userData,
			));
		}else{
			return new JsonModel(array(
				'output' 	=> 'no data',
			));
		}
		/*
		$userData = $userTable->getUserData($user_id)->current();
		echo $_GET['callback'] . '({data:' . json_encode($userData) . '})';
		exit;
		*/
    }
    public function create($data)
    {
		header('Access-Control-Allow-Origin: *');	
		$userTable=$this->getServiceLocator()->get('Models\Model\UserFactory');
		$notificationTable=$this->getServiceLocator()->get('Models\Model\NotificationsFactory');
		$userDetailsTable=$this->getServiceLocator()->get('Models\Model\UserDetailsFactory');
		$userRegistration = $userTable->saveUserData($data);
		$userRegistrationDetails = $userDetailsTable->saveUserDetails($data,$userRegistration);
		$saveregistrationmotification = $notificationTable->sendAdminComplaint($data,'2','0','0','0','1');
		
		if($userRegistrationDetails!=0){
			return new JsonModel(array(
				'UserId'	=>	$userRegistration,
			));
		}else{
			return new JsonModel(array(
				'UserId'	=>	0,
			));
		}
    }
    public function update($uid, $data)
    {
		header('Access-Control-Allow-Origin: *');	
		$userTable=$this->getServiceLocator()->get('Models\Model\UserFactory');
		$userDetailsTable=$this->getServiceLocator()->get('Models\Model\UserDetailsFactory');
		$userRegistration = $userTable->updateUserData($data,$uid);
		$userRegistrationDetails = $userDetailsTable->updateUserDetails($data,$uid);
		if($userRegistrationDetails){
			return new JsonModel(array(
				'value' 	=> 1,
			));
		}else{
			return new JsonModel(array(
				'value' 	=> 0,
			));
		}
    }
    public function delete($id)
    {
       
    }
}